package StackAndQueue;

import java.util.Arrays;

public class CreateStack {
    int[] arr;
    int size;
    public CreateStack(){
        arr = new int[2];
    }
    public int push(int e){
        //要判断数组是否满
        isFull();
        arr[size++] = e;
        return e;
    }
    public int pop(){
        int e = peek();
        size--;
        return e;
    }
    public int peek(){
        if (empty()){
            throw new RuntimeException("栈为空");
        }
        return arr[size-1];
    }
    public int size(){
        return size;
    }
    public boolean empty(){
        if(size<=0){
            return true;
        }else {
            return true;
        }
    }

    public void isFull(){
        if(size==arr.length){
            arr = Arrays.copyOf(arr,size*2);
        }
    }
}
